package com.example.superoa.controller;

import java.sql.Time;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.superoa.model.pojos.KqBanci;
import com.example.superoa.model.service.BanCiService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
public class BanCiController {
	@Autowired
	private BanCiService banci_biz;
	//kq-attendance-rule table初始化值
	@RequestMapping("banci_list")
	@ResponseBody
	public Map<String,Object> banci_list(int page,int rows){
		Map<String,Object> map = new HashMap<>();
		//先分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		JSONArray json = banci_biz.selectAll();
		JSONArray arr=new JSONArray();
		int i=1;
		for (Object object : json) {
			JSONObject obj=(JSONObject)object;
			obj.put("sortable", i);
			i++;
			arr.add(obj);
		}
		//总记录
		map.put("total", pg.getTotal());
		//页内容
		map.put("rows", arr);
		return map;
	}
	@RequestMapping("add_panduan")
	@ResponseBody
	public String panduan(KqBanci banci,Integer id){
		return banci_biz.addpaichong(banci,id);
	}
	//kq-attendance-rule 班次新增确认按钮
	@PostMapping("add_banci")
	public String addBanci(String bid,String bname,int bqi,Time bdao,Time btui) {
		KqBanci pojo=new KqBanci();
		try {
			pojo.setBId(Integer.parseInt(bid));
		} catch (Exception e) {
			// TODO: handle exception
		}
		pojo.setBName(bname);
		pojo.setBQi(bqi);
		pojo.setBDao(bdao);
		pojo.setBTui(btui);
		banci_biz.addBanCi(pojo);
		return "redirect:main-administrator:kq-attendance-rule";
	}
	//kq-attendance-rule 修改查询值
	@RequestMapping("selectBanId")
	@ResponseBody
	public JSONObject initForm(int id) {
		return banci_biz.selectId(id);
	}
}
